package com.baseframe.system.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baseframe.system.entity.BaseNotice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baseframe.system.entity.request.BaseNoticeRequest;
import com.baseframe.system.entity.vo.BaseNoticeVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**

* @description 针对表【base_notice】的数据库操作Mapper
* @createDate 2023-06-23 11:21:11
* @Entity com.baseframe.system.entity.BaseNotice
*/
public interface BaseNoticeMapper extends BaseMapper<BaseNotice> {

    @Select("<script>" +
            "select bn.*,bu.username as publisher_name from base_notice as bn left join base_user bu on bn.publisher = bu.id" +
            "<where>" +
            "bn.is_deleted = 0 " +
            "<if test=\" request.theme!=null &amp;&amp; request.theme !='' \">" +
            "and bn.theme like concat('%',#{request.theme},'%')" +
            "</if>" +
            "</where>" +
            "order by bn.create_time desc" +
            "</script>")
    @Results(
            @Result(column = "publisher_name",property = "publisherName")
    )
    Page<BaseNoticeVO> getPage(Page<BaseNoticeVO> page,@Param("request") BaseNoticeRequest request);

    @Select("select bn.*,bu.username as publisher_name from base_notice as bn left join base_user bu on bn.publisher = bu.id where bn.is_deleted = 0 order by bn.create_time desc limit 5 ")
    @Results(
            @Result(column = "publisher_name",property = "publisherName")
    )
    List<BaseNoticeVO> getNoticeByNew();
}




